<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title>30. 网站用户名验证</title>
    </head>
    <body>
<input type="text" name="username"  />
    </body>
    <script>
        document.querySelector(`[name="username"]`)
        .addEventListener("keyup",e=>{
            const value=e.target.value;
            let reg=/^[a-z][\w-]{2,7}$/i
            console.log(reg.test(value))
        })
       
    </script>
</html>
